#ifndef JTIMER_H
#define JTIMER_H

#include <JXQCore/JMessage>

namespace JXQ
{

class JTimerPrivate;

class JXQLIB_EXPORT JTimer
{
	J_MESSAGE(timeout)

public:
	JTimer();
	~JTimer();

public:
	void start(uint32_t msecs = 1000);
	void stop();

	void setSingleShot(bool flag = true);
	bool isSingleShot() const;

public:
	static void singleStart(uint32_t msecs, std::function<void()> &&callBack);

	template <class Class>
	static void singleStart(uint32_t msecs, Class *obj, void(Class::*method)());

private:
	J_DISABLE_COPY(JTimer)
	JTimerPrivate *d_ptr;
};

template <class Class>
inline void JTimer::singleStart(uint32_t msecs, Class *obj, void(Class::*method)())
{
	singleStart(msecs, std::bind(method, obj));
}

} //namespace JXQ


#endif //JTIMER_H
